$(document).ready(function(){
	
	//上传附件
	$('.addUploadBox').click(function(){
		var id = $(this).attr('val');
		id = parseInt(id)+1;
		if(id>5){
			ui.error('最多只能上传5张图片');
			return false;
		}		
		var uploadBox = '<p>图片'+id+'：<input type="file" name="imgage'+id+'" class="input1" /></p>';
		$('.thumb').append(uploadBox);
		$(this).attr('val',id);
	});
	
	//搜索
	$('.searchButton').click(function(){
		searchAsk();
	})
	//回车事件
});

function askAddCheck(){
	var title = $('#askTitle').val();
	var context = $('#askContext').val();
	if(!_UID_){
		ui.error('请先登录');	
		return false;
	}
	if(title.length>30 || title.length<5){
		ui.error('标题必须5~30个字内,现'+title.length+'个字');	
		return false;
	}	
	if(context.length>10000 || context.length<5){
		ui.error('问题必须5~10000个字之间,现在'+context.length+'个字');
		return false;
	}
}

//加载错误
function error(_this){
	_this.attr('src','/up_files/nopic.png');	
}


//cookie保存访问文章id
function isView(id){
	var cookeName = 'ask@viewIds';
	var arr = new Array();
	var str = $.cookie(cookeName)?$.cookie(cookeName):0;
	if(str){
		arr = str.split(','); 
	}
	if($.inArray(id,arr)>0){
		return true;
	}else{
		var val = str+','+id;
		$.cookie(cookeName,val);
		$.get('/?app=ask&mod=index&act=addViewNum&id='+id);	
		return false;
	}	
}

//增加支持数
function ding(){
	var id = $('.huaMain').attr('vid');
	var cookeName = 'hua@dingIds';
	var arr = new Array();
	var str = $.cookie(cookeName)?$.cookie(cookeName):0;
	if(str){
		arr = str.split(','); 
	}
	if($.inArray(id,arr)>0){
		ui.error('已经表过态了');
	}else{
		var val = str+','+id;
		$.cookie(cookeName,val);
		$.get('/?app=hua&mod=Ajax&act=addDingNum&id='+id,function(rs){
			if(rs==1){
				var dingNum = $('.ding span').html();
				$('.ding span').html(parseInt(dingNum)+1);
				ui.success('表态成功');	
			}
		});	
		return false;
	}		
}

//搜索
function searchAsk(){
	var key = $('#key').val();
	if(!key){
		ui.error('请输入关键字');	
	}else{
		var action = $('#askForm').attr('action');
		window.location.href= action+'&key='+encodeURI(key);
	}
	return false;
}

function ask(){
	var key = $('#key').val();
	var action = $('#askBtn').attr('action');
	$('#askForm').attr('action',action).submit();
}
